package com.itheima.demo04JDBC查询数据_重点;

import java.sql.*;

public class Demo04 {
	public static void main(String[] args) throws SQLException {
		// 1.注册驱动(自动注册)
		// 2.获取连接
		Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql_day2", "root", "root");
		// 3.获取Statement小货车
		Statement statement = connection.createStatement();
		// 4.执行SQL语句
		String sql = "select * from st2";
		ResultSet resultSet = statement.executeQuery(sql);

		// 5.处理结果
		while (resultSet.next()){
			int id = resultSet.getInt("id");
			String name = resultSet.getString("NAME");
			int age = resultSet.getInt("age");
			System.out.println("["+id+"="+name+"="+age+"]");
		}
		// 6.关闭资源
		resultSet.close();
		statement.close();
		connection.close();
	}
}
